package com.shuijianbaozi.teademo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.shuijianbaozi.teademo.R;
import com.shuijianbaozi.teademo.info.NewsInfo;

import java.util.List;

/**
 * Created by bodhixu on 2016/10/11.
 */
public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.MyViewHolder> {

    private Context context;
    private List<NewsInfo.DataBean> datas;

    public NewsAdapter(Context context, List<NewsInfo.DataBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View rootView = LayoutInflater.from(context).inflate(R.layout.item_news, parent, false);

        return new MyViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        NewsInfo.DataBean data = datas.get(position);
        holder.titleTv.setText(data.getTitle());
        holder.timeTv.setText(data.getCreate_time());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        TextView titleTv, timeTv;
        ImageView iv;

        public MyViewHolder(View itemView) {
            super(itemView);

            titleTv = (TextView) itemView.findViewById(R.id.news_title_tv);
            timeTv = (TextView) itemView.findViewById(R.id.news_time_tv);
            iv = (ImageView) itemView.findViewById(R.id.news_image_iv);

        }
    }


}
